#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using Agresso.Interface.Layer.Domain;
using System.Web;
using Agresso.Interface.Layer.Service;
using System.Collections;

#endregion

namespace Agresso.Interface.Layer.Web
{
    public partial class ScheduleTaskForm : Form
    {
        ConfigurationSettingService m_service = new ConfigurationSettingService();
        ConfigurationSetting m_configurationSetting;
        UserControlScheduleTask m_parent;

        public ScheduleTaskForm(ConfigurationSetting configurationSetting,UserControlScheduleTask parent)
        {
            InitializeComponent();
            this.Text = "Schedule Task : " + configurationSetting.setting_name;
            labelTitle.Text = "Schedule Task : " + configurationSetting.setting_name;
            m_configurationSetting = configurationSetting;
            m_parent = parent;
            loadComboDataSource();

            comboBoxTask.Text = configurationSetting.val_1;
            checkBoxEnable.Checked = Convert.ToBoolean(configurationSetting.val_11);
            string[] time = configurationSetting.val_2.Split(':');
            dateTimePicker1.Value = new DateTime(2000, 1, 1, Convert.ToInt16(time[0]), Convert.ToInt16(time[1]), 0);
            labellastExecuteTCRelet.Text = configurationSetting.val_10;
        }

        private void loadComboDataSource()
        {
            IList task = new ArrayList();
            task.Add("Daily");
            //task.Add("Weekly");
            comboBoxTask.DataSource = task;
        }
        private void buttonOK_Click(object sender, EventArgs e)
        {
            try
            {
                UpdateSubject();
                this.Close();
            }
            catch (Exception x)
            {
                MessageBox.Show(x.Message, "Error Exception", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }
        }
        private void UpdateSubject()
        {
            m_configurationSetting.val_1 = comboBoxTask.Text;
            m_configurationSetting.val_2 = dateTimePicker1.Value.Hour + ":" + dateTimePicker1.Value.Minute;
            m_configurationSetting.val_3 = numericUpDownEvery.Value.ToString();
            m_configurationSetting.val_11 = checkBoxEnable.Checked.ToString();
            m_service.UpdateConfiguration(m_configurationSetting);
            m_parent.UpdateConfiguration(m_configurationSetting);
        }
        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonApply_Click(object sender, EventArgs e)
        {
            try
            {
                UpdateSubject();
                buttonApply.Enabled = false;
            }
            catch (Exception x)
            {
                MessageBox.Show(x.Message, "Error Exception", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }
        }
        private void SoftmarVesselMappingForm_Load(object sender, EventArgs e)
        {
            comboBoxTask.Focus();
            dateTimePicker1.ValueChanged += new EventHandler(buttonApplyEnable);
            numericUpDownEvery.ValueChanged += new EventHandler(buttonApplyEnable);
            checkBoxEnable.CheckedChanged += new EventHandler(buttonApplyEnable);
        }
        private void buttonAdvanced_Click(object sender, EventArgs e)
        {
            buttonApply.Enabled = true;
            AdvancedScheduleTaskForm asf = new AdvancedScheduleTaskForm(m_configurationSetting);
            asf.ShowDialog();
        }

        private void buttonApplyEnable(object sender, EventArgs e)
        {
            buttonApply.Enabled = true;
        }

    }
}